package com.hxut.controller;

import com.hxut.dao.UserDao;
import com.hxut.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * description: LoginController
 * date: 2022/6/15 11:34
 * author: MR.孙
 */
@RestController
public class LoginController {
    @Autowired
    private UserDao userDao;

    @PostMapping("/login")
    public Map<String,Object> login(@RequestBody User user){
        Map<String,Object> resultMap=new HashMap<>();
        System.out.println("user->"+user);
        User userMessage = userDao.getUserMessage(user.getUsername(), user.getPassword());
        System.out.println("userMessage->"+userMessage);
        if(userMessage!=null){
            resultMap.put("flag","success");
        }else{
            resultMap.put("flag","error");
        }
        resultMap.put("user",userMessage);
        return resultMap;
    }
}
